﻿package app.view.components.sections.children 
{

	import app.model.types.SectionType;
	import app.model.vo.SectionVO;
	import app.view.components.buttons.GlamurBtnBase;
	import app.view.components.guiDima.switchContent.SwitchContentTextDBase;
	import app.view.components.sections.LabeledSectionBase;
	import app.view.events.UIEvent;
	import flash.events.MouseEvent;
	
	/**
	 * 2.1.1 ЭТАПЫ ПРОВЕДЕНИЯ КОНКУРСА
	 * firsoff maxim, snzflash.com, tel: +79222345364, skype: maxim.firsoff
	 */
	public class ChildrenCompetitionStagesMBase extends LabeledSectionBase
	{
		// app.view.components.sections.children.ChildrenCompetitionStagesMBase
		
		public var winersBtn:GlamurBtnBase;
		public var interveiwBtn:GlamurBtnBase;
		
		public var switchBox:SwitchContentTextDBase;
		
		
		public function ChildrenCompetitionStagesMBase() 
		{
			super();
		}
		
		private function setEvents():void
		{
			winersBtn.addEventListener(MouseEvent.MOUSE_DOWN, onCLickCompetitionWiners);
			interveiwBtn.addEventListener(MouseEvent.MOUSE_DOWN, onCLickInterviewWiners);
			
		}
		
		
		private function removeEvents():void
		{
			winersBtn.removeEventListener(MouseEvent.MOUSE_DOWN, onCLickCompetitionWiners);
			interveiwBtn.removeEventListener(MouseEvent.MOUSE_DOWN, onCLickInterviewWiners);
			
		}
		
		override public function onDestroy():void 
		{
			// чистим что тут есть и вызываем супера
			removeEvents();
			
			winersBtn.destroy();
			interveiwBtn.destroy();
			switchBox.destroy();
			
			
			super.onDestroy();
		};
		
		override public function get data():Object { return _data; };
		
		override public function set data(value:Object):void 
		{
			super.data = value;
			
			setParamHead();
			
			winersBtn.setLang(data.lang);
			interveiwBtn.setLang(data.lang);
			
			//trace('ChildrenCompetitionStagesMBase!!!',_data.data.txt[1].text);
			
			var textArray:Array = new Array();
			
			for each(var object:* in _data.data.txt)
			{
				//trace('object.text',object.text);
				textArray.push( { text:String(object.text).substr(1) } );
			}
			switchBox.data = textArray;
			
			//for (var name:String in _data.data.txt[1]) 
			//{
				//trace('name = ', name);
			//}
			
			setEvents();
		};
		
		/**
		 * переход победители
		 * @param	e
		 */
		private function onCLickCompetitionWiners(e:MouseEvent):void 
		{
			removeEvents();
			
			var obj:SectionVO = new SectionVO();
			obj.id = SectionType.PAGE_CHILDREN_COMPETITION_WINERS;
			obj.currentId = id;
			obj.params = null;
			
			var ev:UIEvent = new UIEvent(UIEvent.SECTION_CHANGE);
			ev.data = obj;
			dispatchEvent(ev);
		}
		/**
		 * переход интервью победителей
		 * @param	e
		 */
		private function onCLickInterviewWiners(e:MouseEvent):void 
		{
			removeEvents();
			
			var obj:SectionVO = new SectionVO();
			obj.id = SectionType.PAGE_CHILDREN_INTERVIEW_WINERS;
			obj.currentId = id;
			obj.params = null;
			
			var ev:UIEvent = new UIEvent(UIEvent.SECTION_CHANGE);
			ev.data = obj;
			dispatchEvent(ev);
		}
	}

}